package com.boodaba.todocarts.domain;

import java.util.List;

import com.boodaba.todocarts.infstr.IStoreContext;

public class LabelRepository implements ILabelRepository {
	private IStoreContext mStoreContext;
	
	public LabelRepository(IStoreContext storeContext) {
		mStoreContext = storeContext;
	}

	@Override
	public List<Label> findAll() {
		return mStoreContext.allOf(Label.class);
	}

	@Override
	public Label getLabelByTitle(String labelTitle) {
		LabelIdSpecification idSpec = new LabelIdSpecification(labelTitle);
		return mStoreContext.getBySpecification(idSpec);
	}

	@Override
	public void save(Label label) {
		mStoreContext.bindBySpecification(label, new LabelIdSpecification(label));
		mStoreContext.save(label);
		mStoreContext.commit();
	}

	@Override
	public void delete(Label label) {
		mStoreContext.bindBySpecification(label, new LabelIdSpecification(label));
		mStoreContext.delete(label);
		mStoreContext.commit();
	}

}
